﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>公告通知管理</title>
    <#include "../common/link.ftl">
    <script>
        $(function () {
            $('.btn-input').click(function () {
                //点击前清空模态框
                $("#noticeForm input").val('');
                $("#noticeForm textarea").val('');
                // 通过事件源.data方法获取自定义属性,会自动封装json详情百度,有则是编辑没有则是添加
                var json = $(this).data("json");
                if (json) {
                    // 给编辑回显数据(id隐藏)
                    $("#noticeForm input[name='id']").val(json.id);
                    $("#noticeForm input[name='title']").val(json.title);
                    $("#noticeForm textarea[name='content']").val(json.content);
                }
                // 点击新增或则编辑弹出模态框
                $('#noticeModal').modal('show');
            });

            //新增编辑模态框的提交按钮
            $('#btn-notice').click(function () {
                //点击提交按钮
                //ajaxSubmit方法可以把表单转为异步的表单，马上提交
                $('#noticeForm').ajaxSubmit(handlerMessage);
            })

            //删除按钮
            $(".btn-delete").click(function () {
                //获取当前点击的公告数据
                var json = $(this).data("json");
                //提示确认框
                $.messager.confirm("警告","是否确认删除公告:"+ json.title +"?",function () {
                    //发送ajax请求
                    $.get('/notice/delete.do',{id:json.id},handlerMessage)
                })
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="notice"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>公告通知管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <form class="form-inline" id="searchForm" action="/notice/list.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <@shiro.hasRole name="admin">
                    <a class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                    </@shiro.hasRole>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <!--高级查询--->
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>公告标题</th>
                            <th>发布人</th>
                            <th>发布时间</th>
                            <th>是否已读</th>
                            <th>操作</th>
                        </tr>
                            <#list (pageResult.list)! as notice>
                            <tr>
                                <td>${(notice_index)!+1}</td>
                                <td>${(notice.title)!}</td>
                                <td>${(notice.issuer.name)!}</td>
                                <td>${(notice.pubdate?string("yyyy-MM-dd"))!}</td>
                                <td>${notice.read?string('已读','未读')}</td>
                                <td>
                                    <a href="/notice/concreteContent.do?noticeId=${(notice.id)!}"
                                       class="btn btn-info btn-xs btn-see" data-json='${(notice.json)!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 查看
                                    </a>
                                    <#-- 管理员才能看 -->
                                    <@shiro.hasRole name="admin">
                                    <a class="btn btn-info btn-xs btn-input" data-json='${(notice.json)!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a class="btn btn-danger btn-xs btn-delete" data-json='${(notice.json)!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 删除
                                    </a>
                                    </@shiro.hasRole>
                                </td>
                            </tr>
                            </#list>
                    </table>
                </form>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<div>
<#-- 新增/编辑模态框 -->
    <div class="modal fade" id="noticeModal" tabindex="-1" role="dialog" aria-labelledby="noticeModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="noticeModalLabel">公告新增/编辑</h4>
                </div>
                <form class="form-horizontal"  method="post" id="noticeForm" action="/notice/saveOrUpdate.do">
                    <div class="form-group" style="margin-top: 10px;">
                    <#-- 公告的id隐藏提交 -->
                        <input type="hidden" name="id"/>
                        <label for="name" class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-8">
                            <input type="text" class="form-control"  name="title"
                                   placeholder="请输入标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-3 control-label">内容：</label>
                        <div class="col-sm-8">
                            <textarea type="text" class="form-control" name="content" cols="10" ></textarea>
                        </div>
                    </div>
                </form>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button id="btn-notice" type="button" class="btn btn-primary">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
